#coding=utf-8
from pymongo import MongoClient
from static.configfile.config import *
import time
url = mongo_url_to_db
url = 'mongodb://127.0.0.1:27017'
client =MongoClient(url)
collection = client["Task"]["doc_xuzhou"]

# pipeline = [{'$group': {'_id': '$channel','count': {'$sum': 1}}}]
# for i in collection.aggregate(pipeline):
#     print(i)

# pipeline = [{'$group': {'_id': {"channel":"$channel",},'count': {'$sum': 1}}}]
# for i in collection.aggregate(pipeline):
#     print(i)

# for i in collection.find({'getTime':{'$regex' : "(\d{4}\-\d{2}\-12)\s.*"}}).limit(10):
#     print(i)

# 转换成标准格式的年月日
# def to_ymd(x) -> str:
#     return time.strftime("%Y-%m-%d",time.localtime(x*86400+28800))

# yarr = {}
# for i in collection.aggregate([{"$project":{"_id":0,"id":1,"channel":1,"getTime":1,"ymd":{"$divide":[{"$subtract":[{"$add":["$getTime",28800]},{"$mod":[{"$add":["$getTime",28800]},86400]}]},86400]}}},{'$group': {'_id': {"channel":'$channel',"ymd":"$ymd"},'count': {'$sum': 1}}},{"$project":{"_id":0,"channel":"$_id.channel","ymd":"$_id.ymd","count":1}}]):
#     yarr.setdefault(i["channel"],{})
#     yarr[i["channel"]][to_ymd(i["ymd"])] = i["count"]

# print(yarr)
# 横坐标，时间轴
# xDataArr = []
# fromdate = "2022-01-11"
# lastdate = "2022-01-14"
# from datetime import datetime,timedelta
# f = [int(y) for y in fromdate.split("-")]
# t = [int(y) for y in lastdate.split("-")]
# td = datetime(t[0], t[1], t[2])
# fd = datetime(f[0], f[1], f[2])
# Days = (td-fd).days
# xDataArr.append(fd.strftime("%Y-%m-%d"))
# for i in range(Days):
#     fd=fd+timedelta(days=+1)
#     xDataArr.append(fd.strftime("%Y-%m-%d"))

# # 纵坐标 每个平台数据量
# legend = list(yarr.keys())
# series =[]
# for l in legend:
#     temp = yarr[l]
#     data = []
#     for d in xDataArr:
#         data.append(temp.setdefault(d,0))
#     y = {
#             "type": 'line',
#             "areaStyle":{},
#             "stack": 'Total'
#         }
#     y["name"] = l
#     y["data"] = data
#     series.append(y)
# print(series)


# 折线图数据参数

# end

# for key in yarr:
#     temp = []
#     for d in date:
#         print(d)
#         # temp.append(yarr[key].setdefault(d,0))
#     print(temp)
#     date.setdefault(i["_id"]["ymd"],1)
# print(date)
# print(date.keys())
# for i in collection.find({"getTime":1620748161}).limit(10):
#     print(i)


x = {
    '山东':[117.000923, 36.675807],
    '河北':[115.48333,38.03333],
    '吉林':[125.35000,43.88333],
    '黑龙江':[127.63333,47.75000],
    '辽宁':[123.38333,41.80000],
    '内蒙古':[111.670801, 41.818311],
    '新疆':[87.68333,43.76667],
    '甘肃':[103.73333,36.03333],
    '宁夏':[106.26667,37.46667],
    '山西':[112.53333,37.86667],
    '陕西':[108.95000,34.26667],
    '河南':[113.65000,34.76667],
    '安徽':[117.283042, 31.86119],
    '江苏':[119.78333,32.05000],
    '浙江':[120.20000,30.26667],
    '福建':[118.30000,26.08333],
    '广东':[113.23333,23.16667],
    '江西':[115.90000,28.68333],
    '海南':[110.35000,20.01667],
    '广西':[108.320004, 22.82402],
    '贵州':[106.71667,26.56667],
    '湖南':[113.00000,28.21667],
    '湖北':[114.298572, 30.584355],
    '四川':[104.06667,30.66667],
    '云南':[102.73333,25.05000],
    '西藏':[91.00000,30.60000],
    '青海':[96.75000,36.56667],
    '天津':[117.20000,39.13333],
    '上海':[121.55333,31.20000],
    '重庆':[106.45000, 29.56667],
    '北京': [116.41667,39.91667],
    '台湾': [121.30, 25.03],
    '香港': [114.10000,22.20000],
    '澳门': [113.50000,22.20000],

}

# collection = client["Task"]["test"]
# with collection.find({},no_cursor_timeout=True) as f:
#     for i in f:
#         print(type(i["canshu"]))
#         print(i["canshu"]["cookies"])
import time
print(time.strftime("%Y-%m-%d",time.localtime()))


   